package Meeting;

import Main.MainJFrame;
import gongju.Communtil;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class MeetingTablePanel extends JInternalFrame{

    private JTextField nameField =new JTextField(10);

    private JTable table = new JTable(){
        public boolean  isCellEditable(int row, int column){
            return false;
        }
    };

    public MeetingTablePanel() {
        super("会议管理",true,true,true,true);
        this.setVisible(true);

        JPanel topPanel=new JPanel();
        this.add(topPanel, BorderLayout.NORTH);
        topPanel.add(new JLabel("会议内容"));
        topPanel.add(nameField);

        JButton searchBtn = new JButton("查询");
        topPanel.add(searchBtn);

        JButton delBtn = new JButton("取消会议");
        topPanel.add(delBtn);

        JPanel panel = new JPanel(new BorderLayout());
        panel.setPreferredSize(new Dimension(900, 350));
        this.add(panel, BorderLayout.CENTER);
        panel.add(table, BorderLayout.CENTER);
        panel.add(table.getTableHeader(), BorderLayout.NORTH);
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        searvh();

        searchBtn.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                searvh();
            }
        });

        delBtn.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                int rowNum=table.getSelectedRow();
                if(rowNum <= -1){
                    return;
                }
                MeetingDAO.remove((int)table.getValueAt(rowNum,0));
                searvh();
            }
        });
    }

    private void searvh(){
        TableModel tablemodel = new DefaultTableModel(
                MeetingDAO.searvhMulti(new int[]{1},new String[]{nameField.getText()}),MeetingDAO.columnNames);
        table.setModel(tablemodel);
    }
}